package com.viphuli.app.tool.fragment;

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.OnClick;

import com.loopj.android.http.RequestParams;
import com.viphuli.app.tool.R;
import com.viphuli.app.tool.bean.part.ArrangeInfo;
import com.viphuli.app.tool.common.AccessTokenKeeper;
import com.viphuli.app.tool.common.MyPageHelper;
import com.viphuli.app.tool.http.ApiRequest;

public class ArrangeRecordDetailArrangeFragment extends BaseProgressFragment {
	
	@Bind(R.id.id_view_week_header)
	protected ViewGroup viewWeekHeaderLayout;

	@Bind(R.id.id_view_week_layout)
	protected ViewGroup viewWeekLayout;

	@Bind(R.id.id_arrange_detail_week_time)
	protected TextView weekTimeText;

	@Bind(R.id.id_arrange_detail_type)
	protected TextView typeText;

	@Bind(R.id.id_arrange_detail_time)
	protected TextView timeText;

	@Bind(R.id.id_arrange_detail_status)
	protected TextView statusText;

	@Bind(R.id.id_arrange_detail_btn_exchange)
	protected TextView submitBtn;

	private int circleId;
	private int arrangeRecordId;
	
	private List<ArrangeInfo> arrangeInfoList;

	@Override
	protected int obtainContentRes() {
		return R.layout.arrange_record_detail_arrange;
	}

	@Override
	protected void initParams() {
		//解析参数
		Bundle args = getArguments();
		circleId = args.getInt("circle_id", 0);
		arrangeRecordId = args.getInt("arrange_record_id", 0);
	}

	@Override
	protected void initView() {

	}

	@Override
	protected void initData() {

		AccessTokenKeeper token = AccessTokenKeeper.readAccessToken(getActivity());

		if (token.isLogin()) {


			RequestParams params = new RequestParams();
			params.put("uid", token.getOpenId());
			params.put("circle_id", circleId);
			params.put("arrange_record_id", arrangeRecordId);

			ApiRequest.arrangeRecordDetailArrange.request(this, params);

		}

	}

	@OnClick(R.id.id_arrange_detail_btn_exchange)
	public void submit() {
		
		Bundle args = new Bundle();
		args.putInt(ArrangeViewFragment.ACTION_TYPE, ArrangeViewFragment.ACTION_EXCHANGE);
		
		ArrangeViewFragment.go(getActivity(), args);
	}

	public TextView getWeekTimeText() {
		return weekTimeText;
	}

	public TextView getTypeText() {
		return typeText;
	}

	public TextView getTimeText() {
		return timeText;
	}

	public TextView getStatusText() {
		return statusText;
	}

	public TextView getSubmitBtn() {
		return submitBtn;
	}

	public ViewGroup getViewWeekLayout() {
		return viewWeekLayout;
	}
	
	public ViewGroup getViewWeekHeaderLayout() {
		return viewWeekHeaderLayout;
	}
	
	public void setArrangeInfoList(List<ArrangeInfo> arrangeInfoList) {
		this.arrangeInfoList = arrangeInfoList;
	}
	
	public List<ArrangeInfo> getArrangeInfoList() {
		return arrangeInfoList;
	}

	public static void go(Activity act, int circleId, int arrangeRecordId) {

		Bundle args = new Bundle();
		args.putInt("circle_id", circleId);
		args.putInt("arrange_record_id", arrangeRecordId);
		MyPageHelper.arrangeRecordDetailArrange.showMyPage(act, args);

	}

}
